package com.sky.controller.admin;

import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Api(tags = "店铺营业状态相关接口")
@Slf4j
@RestController
@RequestMapping("/admin/shop")
public class ShopConstroller {

    public static final String KEY = "sky-take-out:shop:status";

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("查询营业状态")
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        Integer shopStatus = (Integer)redisTemplate.opsForValue().get(KEY);
        log.info("获取到店铺的营业状态为：{}",shopStatus == ShopStatusConstant.BUSINESS ? "营业中" : "打烊中");
        return Result.success(shopStatus);
    }

    @ApiOperation("设置店铺状态")
    @PutMapping("/{status}")
    public Result updateStatus(@PathVariable int status){
        log.info("设置店铺状态为:{}", status == ShopStatusConstant.BUSINESS ? "营业" : "打样");
        redisTemplate.opsForValue().set(KEY, status);
        return Result.success();
    }
}
